<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('告警规则信息列表')" />
</head>
<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="post-form">
					<div class="select-list">
						<ul>
							<li>
								规则名称：<input type="text" name="ruleName"/>
							</li>
							<li>
								告警等级：
								<select name="level" th:with="type=${@dict.getType('alarm_level')}">
									<option value="">所有</option>
									<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
								</select>
							</li>
							<li>
								告警类型：
								<select name="ruleType" th:with="type=${@dict.getType('alarm_rule_list')}">
									<option value="">所有</option>
									<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
								</select>
							</li>
							<li>
								机器是否参与：
								<select name="machineParticipation" th:with="type=${@dict.getType('enum_yes_no')}">
									<option value="">所有</option>
									<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
								</select>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
							    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>

			<div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-success" onclick="$.operate.add()">
	                <i class="fa fa-plus"></i> 新增
	            </a>
				<a class="btn btn-primary single disabled" onclick="$.operate.edit()">
		            <i class="fa fa-edit"></i> 修改
		        </a>
				<a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()">
		            <i class="fa fa-remove"></i> 删除
		        </a>
				<a class="btn btn-warning" onclick="$.table.exportExcel()">
		            <i class="fa fa-download"></i> 导出
		        </a>
	        </div>

	        <div class="col-sm-12 select-table table-striped">
			    <table id="bootstrap-table"></table>
			</div>
		</div>
	</div>
	<th:block th:include="include :: footer" />
	<script th:inline="javascript">
		var alarmLevelDatas = [[${@dict.getType('alarm_level')}]];
		var ruleTypeDatas = [[${@dict.getType('alarm_rule_list')}]];
		var handlingDatas = [[${@dict.getType('enum_yes_no')}]];
		var ruleTypeMap = new Map();
		var prefix = ctx + "system/alarmRule";

		$(function() {
			for (let r of ruleTypeDatas) {
				var value = r.dictValue;
				(function (v) {
					$.get(ctx + "system/dict/data/getType?dictType=" + v, function (data) {
						var list = data.data;
						ruleTypeMap.set(v, list);
					});
				}(value));
			}
			queryList();
		});

		function queryList() {
			var options = {
				url: prefix + "/list",
				createUrl: prefix + "/add",
				updateUrl: prefix + "/edit/{id}",
				removeUrl: prefix + "/remove",
				exportUrl: prefix + "/export",
				sortName: "id",
				sortOrder: "asc",
				modalName: "告警规则数据",
				columns: [{
					checkbox: true
				},
                {
                    field: 'id',
                    title: '编号',
                    sortable: true,
                    visible: false
                },
                {
                    field: 'ruleName',
                    title: '告警规则名称'
                },
                {
                    field: 'ruleType',
                    title: '规则类型',
					formatter: function (value, row, index) {
						return $.table.selectDictLabel(ruleTypeDatas, value);
					}
                },
                {
                    field: 'eventCode',
                    title: '事件编号',
					formatter: function (value, row, index) {
						return $.table.selectDictLabel(ruleTypeMap.get(row.ruleType), value);
					}
                },
				{
					field: 'threshold',
					title: '告警阈值'
				},
                {
                    field: 'level',
                    title: '告警等级',
                    sortable: true,
					formatter: function (value, row, index) {
						return $.table.selectDictLabel(alarmLevelDatas, value);
					}
                },
				{
					field: 'continuousNumber',
					title: '连续次数'
				},
				{
					field: 'machineParticipation',
					title: '机器是否参与',
					formatter: function (value, row, index) {
						return $.table.selectDictLabel(handlingDatas, value);
					}
				},
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        return actions.join('');
                    }
                }]
			};
			$.table.init(options);
		}

	</script>
</body>
</html>